package br.edu.ifrn.potigol.lang;

import br.edu.ifrn.potigol.lang.PotigolClass;
import br.edu.ifrn.potigol.lang.PotigolObject;
import br.edu.ifrn.potigol.lang.PotigolRuntime;

/**
 * Potigol runtime. Ajuda principalmente os métodos para recuperação de valores globais.
 */
public class PotigolRuntime {
  static PotigolClass objectClass;
  static PotigolObject mainObject;
  static PotigolObject nilObject;
  static PotigolObject trueObject;
  static PotigolObject falseObject;
  
  public static PotigolClass getObjectClass() {
    return objectClass;
  }

  public static PotigolObject getMainObject() {
    return mainObject;
  }

  public static PotigolClass getRootClass(String name) {
	//objectClass é nulo quando está inicializando  
    return objectClass == null ? null : (PotigolClass) objectClass.getConstant(name);
  }

  public static PotigolClass getExceptionClass() {
    return getRootClass("Excecao");
  }
  
  public static PotigolObject getNil() {
    return nilObject;
  }
  
  public static PotigolObject getTrue() {
    return trueObject;
  }

  public static PotigolObject getFalse() {
    return falseObject;
  }
  
  public static PotigolObject toBoolean(boolean value) {
    return value ? PotigolRuntime.getTrue() : PotigolRuntime.getFalse();
  }
}
